package com.foreveross.fetl.core.domain.freight.repository.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.foreveross.fetl.common.jpa.EntityHibernateRepository;
import com.foreveross.fetl.core.domain.freight.TaskTimeEntity;
import com.foreveross.fetl.core.domain.freight.repository.ITaskTimeRepository;

@Repository("taskTimeRepository")
public class TaskTimeRepositoryImpl extends EntityHibernateRepository implements
		ITaskTimeRepository {

	@Override
	public List<TaskTimeEntity> findByCode(String channel,String code) {
		return findByCondition(channel,code,null);
	}

	@Override
	public List<TaskTimeEntity> findByCondition(String channel,String code, Integer hour) {
		List<Object> conditionVals = new ArrayList<Object>();
		StringBuilder jpql =new StringBuilder("select task from TaskTimeEntity task where 1=1 ");
		if(channel!=null && !"".equals(channel)){
			jpql.append(" and task.channel = ? ");
			conditionVals.add(channel);
		}
		if(code!=null && !"".equals(code)){
			jpql.append(" and task.taskCode = ? ");
			conditionVals.add(code);
		}
		if(null!=hour ){
			jpql.append(" and task.hour = ? ");
			conditionVals.add(hour);
		}
		List<TaskTimeEntity> list =super.queryResult(jpql.toString(), conditionVals.toArray());
		return list;
	}

}
